<template>
  <div ref="myDiv" class="radar-echart" />
</template>
<script>

export default {
  mounted () {
    this.initChart()
  },
  destroyed () {
    clearInterval(this.timer)
  },
  methods: {
    initChart () {
      // 基于准备好的dom，初始化echarts实例
      this.myChart = this.echarts.init(this.$refs.myDiv)
      // 绘制图表,设置参数
      this.option = {

        tooltip: {},
        radar: {
          // shape: 'circle',
          indicator: [
            { name: '工作效率', max: 100 },
            { name: '考勤', max: 100 },
            { name: '积极性', max: 100 },
            { name: '帮助同事', max: 100 },
            { name: '自主学习', max: 100 },
            { name: '正确率', max: 100 }
          ]
        },
        series: [
          {

            type: 'radar',
            data: [
              {
                value: [10, 1, 100, 5, 100, 0],
                name: '张三'
              },
              {
                value: [50, 50, 50, 50, 50, 10],
                name: '李四'
              }
            ]
          }
        ]
      }
      this.timer = setInterval(() => {
        this.changeChart()
      }, 1000)
    },
    changeChart () {
      const data = []
      for (let index = 0; index < 3; index++) {
        const per = { value: [], name: `李${index}` }
        for (let i = 0; i < 6; i++) {
          per.value.push(Math.floor(Math.random() * 100 + 1))
        }
        data.push(per)
      }
      this.option.series[0].data = data
      this.myChart.setOption(this.option)
    }
  }

}
</script>

// 样式
<style lang="scss">
.radar-echart {
  width: 100%;
  height: 400px;
}
</style>
